test: add focused coverage for upload, queue, and worker paths - #23
Open
usehoplite[bot] wants to merge 2 commits into
Open
test: add focused coverage for upload, queue, and worker paths#23usehoplite[bot] wants to merge 2 commits into
usehoplite[bot] wants to merge 2 commits into
Conversation
Cover the riskiest untested production behavior: - service: CreateAsset presign/public-url/insert flow and MarkAssetUploaded verify-object, transaction, idempotency, and enqueue paths (sqlmock); narrow the storage/queue seams to interfaces used by the flow - queue: Enqueue retry/exhaustion/deadline semantics and option defaults - repository: shouldRetry transient-vs-permanent classification and the broad MIME classifier boundaries - handler: upload validation gates (missing/unsupported content type, oversized, malformed JSON) and mark-uploaded status codes - worker: consume() body-JSON unwrap and routing, job lifecycle (success/done/unknown), dedup branches, plus fixes so the image-pipeline test matches the current content-hash key layout and signature - hoplite: record sandbox setup (Go 1.25 toolchain + worker test deps) Co-authored-by: Shantanu Mane <shantanu.mane.200@outlook.com>
The PR tooling runs git lfs ls-files; fresh sandboxes need the extension installed or first-party PR creation fails. Co-authored-by: Shantanu Mane <shantanu.mane.200@outlook.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds focused tests for the riskiest previously-untested production paths, spanning the Go API (service, queue, handler, repository) and the Python worker (consumer routing/lifecycle, dedup).
Go
internal/service/asset_test.go—CreateAsset(presign → public URL → repo insert → response) andMarkAssetUploaded(object verification before DB, transaction commit + job enqueue, idempotent skip when already uploaded, DB failure rollback, enqueue failure propagation) using fakes +go-sqlmock.internal/queue/queue_test.go—Enqueue/doXAddWithRetryretry-on-transient-failure, retry exhaustion (typedInternalServerError), deadline short-circuit (no retries on canceled ctx), nil-client typed error, and option defaults. Drives a real*redis.Clientthrough a hook, so the full command path is exercised without a Redis server.internal/handler/asset_handler_test.go— upload validation gates (missing/unsupported content type, oversized asset short-circuits before the service, malformed JSON) and mark-uploaded status codes (400 invalid/missing id, 500 service error, 200 success with parsed uuid).internal/repository/retry_test.go—shouldRetrytransient-vs-permanent classification (serialization/deadlock SQLSTATEs, cancellation never retried) andToAssetTypeFromMimeTypeboundaries.Worker (Python)
worker/tests/test_consumer_lifecycle.py— success path marks jobdone+ assetready+ acks; already-done and unknown jobs ack without processing.worker/tests/test_consumer_message.py—consume()unwraps the API's JSONbodyfield and routes byjob_id; asset_id-only routing; malformed message acked; empty poll returns False.worker/tests/test_dedup.py— all fourcheck_for_duplicateoutcomes (no duplicate, pending canonical, ready canonical with variant cloning + canonical link, canonical with no variants → new asset failed, unknown type raises).worker/tests/test_image_pipeline.py— repaired to match the current production signature (content_hash) and content-hash-scoped storage key layout the dedup work introduced.Small production-adjacent changes
internal/service/asset.go— the service struct now holds a narrowobjectStorageinterface (slice ofstoragex.StorageX, whose unexported method blocks external fakes) and the existing-but-unusedqueue.Queueinterface. No behavior change; enables deterministic service tests..hoplite/settings.json— records the sandbox setup (Go 1.25 toolchain via mise, worker test deps in.venv) so fresh sandboxes can run the suites.Verification
go test ./internal/... ./pkg/...— all pass (config, handler, middleware, queue, repository, service, storagex).go vet ./internal/... ./pkg/... ./cmd/...— clean..venv/bin/python -m pytest worker/tests/— 18 passed (was 6 passing + 1 failing due to the signature/format drift).tests/performance_suite_test.gostill requiresPERF_TEST_URLand fails out of the box (t.Fatalwhen unset); left untouched as out of scope for this change.